package com.itfitness.opengldemo

import android.content.Context
import android.opengl.GLSurfaceView
import android.os.Environment
import android.util.Log
import java.io.File
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

/**
 *
 * @ProjectName:    OpenGLDemo
 * @Package:        com.itfitness.opengldemo
 * @ClassName:      GLRender
 * @Description:     java类作用描述
 * @Author:         itfitness
 * @CreateDate:     2022-11-24 11:25
 * @UpdateUser:     更新者：
 * @UpdateDate:     2022-11-24 11:25
 * @UpdateRemark:   更新说明：
 */
class GLRender(val context:Context) : GLSurfaceView.Renderer{
    init {
        System.loadLibrary("CCOpenGLRender")
    }
    private external fun ndkInitGL()
    private external fun ndkPaintGL()
    private external fun ndkResizeGL(width:Int,height:Int)
    private external fun ndkLoadGLTexTureID(fileName:String)
    override fun onSurfaceCreated(p0: GL10?, p1: EGLConfig?) {
        //初始化
        ndkInitGL()
        val file = File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),"texture/rabit.png")
        if(file.exists()){
            Log.e("测试",file.absolutePath)
            ndkLoadGLTexTureID(file.absolutePath)
        }
    }

    override fun onSurfaceChanged(p0: GL10?, p1: Int, p2: Int) {
        //改变大小
        ndkResizeGL(p1,p2)
    }

    override fun onDrawFrame(p0: GL10?) {
        //绘制
        ndkPaintGL()
    }
}